#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
using namespace std;
int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    while (n)
    {
        if (n - a < 0 && n - b >= 0)
        {
            cout << n % b;
            return 0;
        }
        if (n - b < 0 && n - a >= 0)
        {
            cout << n % a;
            return 0;
        }
        if (n - a < 0 && n - b < 0)
        {
            cout << n;
            return 0;
        }
        int tmp1 = min(n % a, n % b);
        if (tmp1 == n % a)
            n -= a;
        else
            n -= b;
    }
    cout << n;
    return 0;
}